﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Web.Caching;

public partial class WebService_Components_Methods : GetTogether.Studio.Web.UI.Control
{
    private string _Error;

    public new string Error
    {
        get { return _Error; }
        set { _Error = value; }
    }

    public GetTogether.Studio.WebService.ProjectParameter Parameter;

    public System.Collections.Generic.List<System.Reflection.MethodInfo> Methods;
    public bool IsProxy = false;
    public Dictionary<string, List<string>> Caches;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsProxy)
        {
            Caches = GetCaches();
        }
        rptResult.DataSource = Methods;
        rptResult.DataBind();
    }

    public Dictionary<string, List<string>> GetCaches()
    {
        Cache _cache = HttpRuntime.Cache;
        IDictionaryEnumerator cacheEnum = _cache.GetEnumerator();
        Dictionary<string, List<string>> ret = new Dictionary<string, List<string>>();
        string currentProxyKey = string.Concat("Proxy", "|", CurrentSession.UserCode, "|", Parameter.ProjectName);
        while (cacheEnum.MoveNext())
        {
            string key = cacheEnum.Key.ToString();
            string[] keyInfo = key.Split('|');


            if (key.StartsWith(currentProxyKey) && keyInfo.Length > 3)
            {
                string methodName = keyInfo[3];
                if (!ret.ContainsKey(methodName)) ret[methodName] = new List<string>();
                ret[methodName].Add(cacheEnum.Key.ToString());
            }
        }
        return ret;
    }

    public string GetCacheInfo(string methodName)
    {
        if (Caches != null && Caches.ContainsKey(methodName)) return " Caches(" + Caches[methodName].Count.ToString() + ")";
        return string.Empty;
    }

    public string GetProxyCaseInfo(string methodName)
    {
        List<string> cases = GetTogether.Studio.WebService.WebServiceProxyHelper.GetProxyCases(CurrentSession.UserCode, Parameter.ProjectName, methodName);
        if (cases != null && cases.Count>0) return " Cases(" + cases.Count.ToString() + ")";
        return string.Empty;
    }
}